package com.bzframework.pro.web;

import com.bzframework.pro.authorize.annotation.Authorization;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.net.URI;
import java.util.Arrays;

/**
 * @Author bingzhong
 * @Date 2025/4/26 16:21
 * @Description
 */
@RestController
@RequestMapping("/test")
public class TestController {

    @GetMapping("/old-url")
    @Authorization(ignore = true)
    public Mono<Void> redirect(ServerWebExchange exchange) {
        return Mono.fromRunnable(() -> {
            exchange.getResponse().setStatusCode(HttpStatus.PERMANENT_REDIRECT);
            exchange.getResponse().getHeaders().setLocation(URI.create("https://www.baidu.com/"));
        });
    }

    @GetMapping("/get")
    @Authorization(ignore = true)
    public Mono<String> get(@RequestParam String orgId, @RequestParam String mode){

        return Mono.just(orgId + "mode:" + mode);

    }

    @GetMapping("/fetch")
    @Authorization(ignore = true)
    public Mono<Template> fetch(){

        Template template = new Template();
        template.setText("推荐");
        Template.Options options = new Template.Options();
        options.setTitle("标题");
        Template.Meta meta = new Template.Meta();
        meta.setInstanceId("111");
        meta.setImage("111");
        meta.setDescription("2222");
        options.setMeta(meta);
        template.setOptions(Arrays.asList(options));

        return Mono.just(template);

    }

    @GetMapping("/put")
    @Authorization(ignore = true)
    public Mono<Template> put(){

        Template template = new Template();
        template.setText("推荐");
        Template.Options options = new Template.Options();
        options.setTitle("标题");
        Template.Meta meta = new Template.Meta();
        meta.setInstanceId("111");
        meta.setImage("111");
        meta.setDescription("2222");
        options.setMeta(meta);
        template.setOptions(Arrays.asList(options));

        return Mono.just(template);

    }




    @GetMapping("/lookup")
    @Authorization(ignore = true)
    public Mono<String> lookup(@RequestParam String q){

        return Mono.just(q);

    }


}
